package com.gmt;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author John.zhang
 * @version Id: UserController, v 1.0 2020/11/16 13:55 ZhiYong Exp $
 */

@RestController
public class UserController {

    @Value("${product.service.url}")
    private String productServiceUrl;

    @Resource
    private RestTemplate restTemplate;

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    @GetMapping("product/{id}")
    public String queryProductInfo(@PathVariable("id") int id) {
        //根据应用名称去获取服务提供的地址信息
        return restTemplate.getForObject(productServiceUrl + "/product/" + id, String.class);
    }

}
